package com.mew.lobby.handler.sms;

import com.mew.common.config.RedisConstantValue;
import com.mew.common.exception.ResponseCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class SMSValidService {

    @Autowired
    private RedisTemplate<String,Object> redisTemplate;

    public int authCode(String tel, String authCode) {

        if (tel.length()==11&&"95279527".equals(authCode)){
            return ResponseCode.Success.code();
        }

        String rand = (String) redisTemplate.opsForValue().get(RedisConstantValue.USER_SMS + tel);

        if (null==rand||!rand.equals(authCode)){
            return ResponseCode.AuthCode.code();
        }
        redisTemplate.delete(RedisConstantValue.USER_SMS + tel);
        return ResponseCode.Success.code();
    }

}
